#include <iostream>
#include <string>
#include <pthread.h>
#include <unistd.h>
#include <cstdio>
#include <cerrno>
#include <cstdlib>
#include <string.h>
using namespace std;


void *startRoutine(void *args)
{
    string name = (char *)args;
    while (true)
    {
        cout << name << " : " << ::getpid() << endl;
        sleep(1);
    }
}

int main()
{
    pthread_t tid;
    int count = 0;
    pthread_create(&tid, nullptr, startRoutine, (void *)"thread 1");

    while (true)
    {
        cout << "我是主线程..." << ::getpid() << endl;
        sleep(2);
    }
    return 0;
}

// int g_val = 5;

// int main()
// {
//     pid_t id = vfork();
//     if (id == 0)
//     {
//         g_val = 7;
//         cout << "I am a child process , pid : " << getpid() << "   g_val = " << g_val << endl;
//         exit(0);
//     }
//     sleep(2);
//     cout << "I am a parent process , pid : " << getpid() << "   g_val = " << g_val << endl;
//     return 0;
// }